const { DataTypes } = require('sequelize');
const sequelize = require('@shared/utils/database');
const { PRODUCT } = require('@shared/constants');

const Product = sequelize.define('Product', {
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true,
    comment: '商品ID'
  },
  category_id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    comment: '分类ID'
  },
  name: {
    type: DataTypes.STRING(64),
    allowNull: false,
    comment: '商品名称'
  },
  cover: {
    type: DataTypes.STRING(256),
    allowNull: false,
    comment: '商品封面图'
  },
  gallery: {
    type: DataTypes.JSON,
    comment: '商品图片集'
  },
  original_price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '原价'
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '售价'
  },
  stock: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '库存'
  },
  sales: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '销量'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '商品描述'
  },
  status: {
    type: DataTypes.TINYINT,
    allowNull: false,
    defaultValue: PRODUCT.STATUS.ON_SHELF,
    comment: '状态：0-下架 1-上架'
  },
  recommend: {
    type: DataTypes.TINYINT,
    allowNull: false,
    defaultValue: 0,
    comment: '是否推荐：0-不推荐 1-推荐'
  }
}, {
  tableName: 'product',
  timestamps: true,
  createdAt: 'create_time',
  updatedAt: 'update_time'
});

module.exports = Product; 